using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class enemy : MonoBehaviour
{
    // Start is called before the first frame update
    private Transform frontCheck;
    private Rigidbody2D enemybody;
    public float enemySpeed = 20f;
    public float health = 2.0f;

    void Start()
    {
        frontCheck=transform.Find("FrontCheck").transform;
        enemybody = GetComponent<Rigidbody2D>();

        
    }

    // Update is called once per frame
    void Update()
    {
        Collider2D[] cols = Physics2D.OverlapPointAll(frontCheck.position, 1);
        foreach (Collider2D col in cols)
        {
            if (col.tag == "Tower")
            {
                Flip();
                break;

            }
        }

        enemybody.velocity = new Vector2(enemySpeed * transform.localScale.x, enemybody.velocity.y);
       
    }
    void Flip()
    {
        Vector3 localscale = transform.localScale;
        localscale.x *= -1;
        transform.localScale = localscale;
       
    }

}
